package org.ouwh.fw.model.data;

import java.io.Serializable;

import org.ouwh.fw.util.xml.Node;

public class Data implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7327754380944133254L;

	private static final String DATA = "data";

	protected String name;

	protected Object value;

	protected String tagName;

	protected static int tabCount = 0;

	public Data() {
		this.tagName = DATA;
	}

	public Data(String name) {
		this.name = name;
		this.tagName = DATA;
	}

	public Data(String name, Object value) {
		this.name = name;
		this.value = value;
	}

	public void addData(Data data) {
	}

	public String getName() {
		return name;
	}

	public Object getValue() {
		return value;
	}

	public Object init(Node node) {
		try {
			tagName = node.getXmlType();
			String id = node.getXmlAttr("id").toString();
			this.setName(id);
		} catch (Exception e) {
		}
		try {
			this.setValue(node.getXmlAttr("value"));
		} catch (Exception ee) {
		}
		return null;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public String toString() {
		StringBuffer tmp = new StringBuffer();
		for (int i = 0; i < tabCount; i++) {
			tmp.append('\t');
		}
		tmp.append('<');
		tmp.append(tagName);
		tmp.append(" id=\"");
		tmp.append(name);
		tmp.append("\" value=\"");
		tmp.append(value);
		tmp.append("\" />\n");
		return tmp.toString();
	}

	public Object clone() throws CloneNotSupportedException {
		Data data = new Data(name, value);
		data.tagName = this.tagName;
		return data;
	}

}
